﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Small.Util.IO
{
  public  class FileHandler
    {
       bool flag = false;
        /// <summary>
        /// 创建一个文件并写入
        /// </summary>
        /// <param name="path"></param>
        /// <param name="fileContent"></param>
        /// <returns></returns>
        public bool CreateFile(string path, byte[] fileContent)
        {
            flag = false;

            return flag;
        }
        /// <summary>
        /// 复制文件
        /// </summary>
        /// <param name="oldFileName"></param>
        /// <param name="newFileName"></param>
        /// <returns></returns>
        public  bool CopyFile(string oldFileName, string newFileName)
        {
           flag = false;
          try
          {
              if (File.Exists(oldFileName))
              {
                  File.Copy(oldFileName, newFileName, true);
                  flag = true;
              }
          }
          catch (Exception ex)
          {

              throw new Exception(ex.Message);
          }
          


            return flag;
        }
        /// <summary>
        /// 移动文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="newFileName"></param>
        /// <returns></returns>
        public bool MoveFile(string fileName, string newFileName)
        {
            flag = false;

            if (File.Exists(fileName)) 
            {
                string directory = Path.GetDirectoryName(newFileName);
                if (!Directory.Exists(directory)) 
                {
                    Directory.CreateDirectory(directory);
                }
                File.Move(fileName, newFileName);
                flag = true;
            }
            return flag;
        }
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public bool DeleteFile(string fileName)
        {
            flag = false;

            if (FileExist(fileName)) 
            {
                File.Delete(fileName);
                flag = true;
            }
            return flag;
        }
      /// <summary>
      /// 判断文件是否存在
      /// </summary>
      /// <param name="filePath"></param>
      /// <returns></returns>
        private bool FileExist(string filePath) 
        {
            return File.Exists(filePath);
        }

      
       
    }
}
